﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.Sinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sinv_CustomerController : ControllerBase
    {
        private readonly ISinv_CustomerService sinv_CustomerService;
        private readonly IMapper mapper;

        public Sinv_CustomerController(ISinv_CustomerService sinv_CustomerService,IMapper mapper)
        {
            this.sinv_CustomerService = sinv_CustomerService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 分页条件查询客户信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_CustomerAsync(string? name, string? phone, int currentPage, int pageSize)
        {
            return new JsonResult(await sinv_CustomerService.GetSinv_CustomerAsync(name,phone,currentPage,pageSize));
        }

        /// <summary>
        /// 条件查询客户总数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_CustomerCountAsync(string? name, string? phone)
        {
            return new JsonResult(await sinv_CustomerService.GetSinv_CustomerCountAsync(name,phone));
        }

        /// <summary>
        /// 逻辑删除客户信息
        /// </summary>
        /// <param name="sinv_CustomerDelDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_CustomerDelAsync(Sinv_CustomerDelDto sinv_CustomerDelDto)
        {
            return new JsonResult(await sinv_CustomerService.Sinv_CustomerDelAsync(sinv_CustomerDelDto));
        }

        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="sinv_CustomerAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Sinv_CustomerAddAsync(Sinv_CustomerAddDto sinv_CustomerAddDto)
        {
            return new JsonResult(await sinv_CustomerService.Sinv_CustomerAddAsync(sinv_CustomerAddDto));
        }

        /// <summary>
        /// 根据客户编号查询对应客户信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_CustomerByCodeAsync(string code)
        {
            return new JsonResult(await sinv_CustomerService.Sinv_CustomerByCodeAsync(code));
        }

        /// <summary>
        /// 修改客户信息
        /// </summary>
        /// <param name="sinv_CustomerUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_CustomerUpdateAsync(Sinv_CustomerUpdateDto sinv_CustomerUpdateDto)
        {
            return new JsonResult(await sinv_CustomerService.Sinv_CustomerUpdateAsync(sinv_CustomerUpdateDto));
        }

        /// <summary>
        /// 根据客户名称查询客户信息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_CustomerByNameAsync(string? name)
        {
            return new JsonResult(await sinv_CustomerService.Sinv_CustomerByNameAsync(name));
        }
    }
}
